package com.sunyard.springcloudhystrix.Resilience4j;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.stereotype.Service;

/**
 * @author zyl
 * @description
 * @since 2025/7/14
 */
@Service
public class PaymentService {
    // 模拟支付服务（失败率40%）
    @CircuitBreaker(name = "orderService", fallbackMethod = "processPaymentFallback")
    public String processPayment(String paymentId) {
        if (Math.random() < 0.9) {
            throw new RuntimeException("Payment Service Error!");
        }
        return "Processed-" + paymentId;
    }

    // 降级方法（需与原方法参数一致，最后加异常参数）
    public String processPaymentFallback(String paymentId, Exception e) {
        return "[Fallback] Payment-" + paymentId;
    }
}
